package com.situ.day7;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

import org.junit.Test;


public class ArrayListDemo {
	public static void main(String[] args) {
		Student[] students = new Student[3];
		Student student1 = new Student(1, "zhangsan1", 20, "Java");
		Student student2 = new Student(2, "zhangsan2", 20, "Java");
		Student student3 = new Student(3, "zhangsan3", 20, "Java");
		students[0] = student1;
		students[1] = student2;
		students[2] = student3;
		for (int i = 0; i < students.length; i++) {
			System.out.println(students[i]);
		}
		// <Studnet>表示ArrayList里面只能放Student
		ArrayList<Student> list = new ArrayList<>();
		list.add(student1);
		list.add(student2);
		list.add(student3);
		//list.remove(0);
		//list.remove(student2);
		//list.add(1);
		//list.add("Hello");
		//1、数组方式遍历
		for (int i = 0; i < list.size(); i++) {
			Student student = (Student)list.get(i);
			System.out.println(student);
		}
		System.out.println("------------");
		//2、foreach
		for (Student student : list) {
			System.out.println(student);
		}
	}
	
	@Test
	public void test233() {
		//List<Student> list1 = new ArrayList<>();
		ArrayList<Student> list = new ArrayList<>();
		Student student1 = new Student(1, "zhangsan1", 20, "Java");
		Student student2 = new Student(2, "zhangsan2", 20, "Java");
		Student student3 = new Student(3, "zhangsan3", 20, "Java");
		list.add(student1);
		list.add(student2);
		list.add(student3);
		list.add(student3);
		list.add(student3);
		for (Student student : list) {
			System.out.println(student);
		}
		System.out.println("---------");
		//Set<Student> set = new HashSet<>();
		HashSet<Student> set = new HashSet<>();
		set.add(student1);
		set.add(student2);
		set.add(student3);
		set.add(student3);
		set.add(student3);
		for (Student student : set) {
			System.out.println(student);
		}
	}
	
	@Test
	public void test434() {
		// CN     中华人民共和国
		// US     美利坚合众国
		// key    value
		HashMap<String, String> map = new HashMap<>();
		map.put("CN", "中华人民共和国");
		map.put("US", "美利坚合众国");
		//根据key，找到这个key对应的这个值value
		String value1 = map.get("CN");
		System.out.println(value1);
		System.out.println("------------");
		// Map遍历
		Set<Entry<String, String>> entrySet = map.entrySet();
		for (Entry<String, String> entry : entrySet) {
			String key = entry.getKey();
			String value = entry.getValue();
			System.out.println("key: " + key);
			System.out.println("value: " + value);
		}
		System.out.println("------------");
		// keySet将map里面所有的key放到set集合
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			System.out.println("key： " + key);
			String value = map.get(key);
			System.out.println("value: " + value);
		}
	}
	
	
	
}
